# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/21 下午5:44
 @Author  : tgy
 
"""
import re

text = 'yeah, but no, but yeah, but no, but yeah'
text1 = 'cc11/27/2012ddd09/11/2021'

def test01():
    ...
    # 没有找到 返回 -1
    print(text.find('no'))
    # 如果没有找到，抛ValueError异常
    print(text.index('tt'))


def test02():
    ...
    p = re.compile(r'\w+')
    print(type(p.match(text)))
    # match 从头开始匹配，匹配到了返回Match对象，没有匹配到返回None
    if p.match(text):
        print('匹配到了')
    else:
        print('木有匹配到')


def test03():
    ...
    pattern = re.compile(r'(\d+)/(\d+)/(\d+)')
    # if pattern.match(text1):
    #     ...
    #     print('11')
    # else:
    #     print('222')
    # t1 = pattern.match(text1).group()
    # print(t1)
    # search 查找字符串中匹配的字符，匹配到一次之后就返回
    print(pattern.search(text1).groups())
    # match 从字符串开头配置，如果开头不匹配直接返回，开头匹配到就返回开头匹配到的字符串
    # print(pattern.match(text1).groups())
    # for t in pattern.finditer(text1):
    #     print(t.groups())


if __name__ == '__main__':
    ...
    test03()